package com.shivandragon.utils;

import javax.servlet.http.HttpServletRequest;

public class AuthorizationManager {

	public enum Authorization {ADMIN, VIEWER}
	
	public Authorization getAuthorisation(HttpServletRequest request) {
		String a = (String)(request.getAttribute("a") == null? request.getSession().getAttribute("a") : request.getAttribute("a"));
		if (a == null) {
			a = request.getParameter("a");
		}
		String v = (String)(request.getAttribute("v") == null? request.getSession().getAttribute("v") : request.getAttribute("v"));
		if (v == null) {
			v = request.getParameter("v");
		}
		if(a!=null && a.equals(Constants.ADMIN_TOKEN))  {
			return Authorization.ADMIN;
		} else if (v!=null && v.equals(Constants.VIEWER_TOKEN)) {
			return Authorization.VIEWER;
		} else  {
			return null;
		}
		
	}
}
